package user

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"project-im/config"
	"project-im/internal/api/response"
	"project-im/internal/model/dao"
)

func FindFriendByName(c *gin.Context) {
	var two []*response.Friend
	//value, _ := c.Get("userId")
	name := c.Query("name")
	var user []dao.ImUser
	config.DB.Where("user_name like ? or nick_name like ?", "%"+name+"%", "%"+name+"%").Find(&user)
	for _, imUser := range user {
		friend := response.Friend{
			ID:             int(imUser.ID),
			UserName:       imUser.UserName,
			NickName:       imUser.NickName,
			Sex:            int(imUser.Sex),
			Type:           int(imUser.Type),
			Signature:      imUser.SigNature,
			HeadImage:      imUser.HeadImage,
			HeadImageThumb: imUser.HeadImageThumb,
			IsBanned:       false,
			IsInBlacklist:  nil,
			Status:         0,
			Online:         false,
		}
		two = append(two, &friend)
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "成功",
		"data":    two,
	})
}

func Find(c *gin.Context) {
	value := c.Param("id")
	var user dao.ImUser
	config.DB.Where("id=?", value).Limit(1).Find(&user)
	c.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "成功",
		"data":    user,
	})
}
